package org.oos.atom.entries.impl;

import org.oos.atom.elements.AbstractOosEntry;
import org.oos.atom.elements.Author;
import org.oos.atom.elements.AuthorElement;
import org.oos.atom.elements.Text;
import org.oos.atom.entries.UserEntry;
import org.oos.model.UserAvatar;

import com.google.api.client.util.Key;

public class UserEntryImpl extends AbstractOosEntry implements UserEntry, Cloneable {

	private static final long serialVersionUID = -7880421388115792490L;

	@Key("oos:mail")
	private String mail;

	@Key("oos:name")
	private String name;

	@Key("oos:slug")
	private String slug;

	@Key("oos:surname")
	private String surname;

	@Key("oos:telephone")
	private String telephone;

	@Key("oos:nomails")
	private String nomails;

	@Key("oos:nonewsletter")
	private String nonewsletter;

	@Key("oos:onlycontacts")
	private String onlycontacts;

	@Key("oos:nobulletin")
	private String nobulletin;

	@Key("oos:nomailonmediacomments")
	private String nomailonmediacomments;

	@Key("oos:nomailonlikes")
	private String nomailonlikes;

	@Key("oos:nomailoncommentsonreview")
	private String nomailoncommentsonreview;

	@Key("oos:nosuggestedcontacts")
	private String nosuggestedcontacts;

	@Key("oos:twitter")
	private String twitter;

	@Key("oos:facebook")
	private String facebook;
	
	public UserEntryImpl() {}
	
	public UserEntryImpl(Author author) {
		this.author = new AuthorElement(author);
		this.setNick(author.getNick());
		this.slug = author.getSlug();
	}

	@Override
	public UserAvatar getAvatar() {
		return this.getAuthor().getAvatar();
	}

	@Override
	public Text getAboutMe() {
		return this.content;
	}
	
	@Override
	public void setAboutMe(Text about) {
		this.content = about;
	}

	@Override
	public String getMail() {
		return mail;
	}
	
	@Override
	public void setMail(String mail) {
		this.mail = mail;
	}

	@Override
	public String getName() {
		return name;
	}
	
	@Override
	public void setName(String name) {
		this.name = name;
	}

	@Override
	public String getNick() {
		return this.title.getValue();
	}
	
	@Override
	public void setNick(String nick) {
		this.title = new Text(nick);
	}

	@Override
	public String getSlug() {
		return slug;
	}
	
	@Override
	public void setSlug(String slug) {
		this.slug = slug;
	}

	@Override
	public String getSurname() {
		return surname;
	}
	
	@Override
	public void setSurname(String surname) {
		this.surname = surname;
	}

	@Override
	public String getTelephone() {
		return telephone;
	}
	
	@Override
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	
	private Boolean stringToBoolean(String str) {
		if (str == null) {
			return null;
		} else if (str.equals("true")) {
			return true;
		} else {
			return false;
		}
	}
	
	private String booleanToStr(Boolean bool) {
		if (bool == null) {
			return null;
		} else if (bool) {
			return "true";
		} else {
			return "false";
		}
	}

	@Override
	public Boolean getNobulletin() {
		return stringToBoolean(nobulletin);
	}

	@Override
	public Boolean getNomailoncommentsonreview() {
		return stringToBoolean(nomailoncommentsonreview);
	}

	@Override
	public Boolean getNomailonlikes() {
		return stringToBoolean(nomailonlikes);
	}

	@Override
	public Boolean getNomailonmediacomments() {
		return stringToBoolean(nomailonmediacomments);
	}

	@Override
	public Boolean getNomails() {
		return stringToBoolean(nomails);
	}

	@Override
	public Boolean getNonewsletter() {
		return stringToBoolean(nonewsletter);
	}

	@Override
	public Boolean getNosuggestedcontacts() {
		return stringToBoolean(nosuggestedcontacts);
	}

	@Override
	public Boolean getOnlycontacts() {
		return stringToBoolean(onlycontacts);
	}

	@Override
	public void setNobulletin(Boolean bool) {
		this.nobulletin = booleanToStr(bool);
	}

	@Override
	public void setNomailoncommentsonreview(Boolean bool) {
		this.nomailonmediacomments = booleanToStr(bool);
	}

	@Override
	public void setNomailonlikes(Boolean bool) {
		this.nomailonlikes = booleanToStr(bool);
	}

	@Override
	public void setNomailonmediacomments(Boolean bool) {
		this.nomailonmediacomments = booleanToStr(bool);
	}

	@Override
	public void setNomails(Boolean bool) {
		this.nomails = booleanToStr(bool);
	}

	@Override
	public void setNonewsletter(Boolean bool) {
		this.nonewsletter = booleanToStr(bool);
	}

	@Override
	public void setNosuggestedcontacts(Boolean bool) {
		this.nosuggestedcontacts = booleanToStr(bool);
	}

	@Override
	public void setOnlycontacts(Boolean bool) {
		this.onlycontacts = booleanToStr(bool);
	}

	@Override
	public Boolean getTwitter() {
		return stringToBoolean(twitter);
	}
	
	@Override
	public void setTwitter(Boolean bool) {
		this.twitter = booleanToStr(bool);
	}

	@Override
	public Boolean getFacebook() {
		return stringToBoolean(facebook);
	}
	
	@Override
	public void setFacebook(Boolean bool) {
		this.facebook = booleanToStr(bool);
	}
}
